<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>添加宝宝</title>
		<meta name="description" content="">
		<meta name="keywords" content="">
		<meta name="renderer" content="webkit">
		<!-- 设置缩放 -->
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui" />
		<!-- 可隐藏地址栏，仅针对IOS的Safari（注：IOS7.0版本以后，safari上已看不到效果） -->
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<!-- 仅针对IOS的Safari顶端状态条的样式（可选default/black/black-translucent ） -->
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<!-- IOS中禁用将数字识别为电话号码/忽略Android平台中对邮箱地址的识别 -->
		<meta name="format-detection" content="telephone=no, email=no" />
		<!-- 启用360浏览器的极速模式(webkit) -->
		<meta name="renderer" content="webkit">
		<!-- 避免IE使用兼容模式 -->
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<!-- 针对手持设备优化，主要是针对一些老的不识别viewport的浏览器，比如黑莓 -->
		<meta name="HandheldFriendly" content="true">
		<!-- 微软的老式浏览器 -->
		<meta name="MobileOptimized" content="320">
		<!-- uc强制竖屏 -->
		<meta name="screen-orientation" content="portrait">
		<!-- QQ强制竖屏 -->
		<meta name="x5-orientation" content="portrait">
		<!-- UC强制全屏 -->
		<meta name="full-screen" content="yes">
		<!-- QQ强制全屏 -->
		<meta name="x5-fullscreen" content="true">
		<!-- UC应用模式 -->
		<meta name="browsermode" content="application">
		<!-- QQ应用模式 -->
		<meta name="x5-page-mode" content="app">
		<!-- windows phone 点击无高光 -->
		<meta name="msapplication-tap-highlight" content="no">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="icon" type="image/png" href="../assets/i/favicon.png">
		<link rel="stylesheet" href="../assets/choice/iosSelect.css">
		<link rel="stylesheet" href="../assets/css/LArea.css">
		<link rel="stylesheet" href="../assets/css/amazeui.css" />
		<link rel="stylesheet" href="../assets/css/beans.css" />
		<style>
			.am-list-news-default .am-list-item-hd {
			    white-space: nowrap;
			    text-overflow: ellipsis;
			    overflow: hidden;
			    width: 78%;
			}
		</style>
	</head>
	<body>
		<header data-am-widget="header" class="am-header am-header-default bg-48CFAE">
			<div class="am-header-left am-header-nav text-black padding-left05" id="goBackDivs">
				<a  href="javascript:history.go(-1)" class="text-black" id="goBackIcon">
				  	<i class="am-align-left am-margin-0 am-icon-angle-left am-icon-md text-black co-fff"></i>
				  </a> 
			</div>
			<h1 class="am-header-title teblack">
				<a href="#title-link" class="co-fff">添加宝宝</a>
			</h1>
		</header>
		<div>
			<h2 class="yimiaoh3">宝宝基本信息</h2>
			<div style="background-color: white;" class="am-margin-top-sm">
				<div data-am-widget="list_news" class="am-list-news am-list-news-default am-margin-top-sm" style="margin-top: 0;">
				  	<!--列表标题-->
				  	<div class="am-list-news-bd">
				  		<ul class="am-list am-margin-bottom-sm">
							<li class="am-g am-list-item-dated">
				          		<a href="##" class="am-list-item-hd namethe" onclick="return false" style="margin-left: 0.5rem;">
				          			<img src="../img/user.png">
				          			<input placeholder="请选择我与宝宝的关系" id="between" readonly/>
				          		</a>
							</li>
							<li class="am-g am-list-item-dated">
				          		<a href="##" class="am-list-item-hd namethe" onclick="return false" style="margin-left: 0.5rem;">
				          			<img src="../img/sex.png">
				          			<input placeholder="宝宝姓名" id="childName" />
				          		</a>
				          		<span class="am-list-date">
				          			<label class="boy select" style="color:#46c8ff;">
				          				<img src="../img/boy1.png"> 
				          				<span>男</span>
				          			</label>
				          			<label class="girl">
				          				<img src="../img/girl.png">
				          				<span>女</span>
				          			</label>
				          		</span>
							</li>
							<li class="am-g am-list-item-dated">
				          		<a href="##" class="am-list-item-hd namethe" onclick="return false" style="margin-left: 0.5rem;">
				          			<img src="../img/birthday.png">
				          			<input required readonly type="text" id="childuserBirthday" value="" placeholder="宝宝出生年月" style="background-color: white;">
				          		</a>
							</li>
							<li class="am-g am-list-item-dated">
				          		<a href="##" class="am-list-item-hd namethe" onclick="return false" style="margin-left: 0.5rem;" >
				          			<img src="../img/location.png" style="width: 17px;">     
				          			<input id="address" placeholder="选择接种所在地" readonly/>
           	 						<input id="value2" type="hidden"/>
				          		</a>
							</li>
							<li class="am-g am-list-item-dated">
				          		<a href="##" class="am-list-item-hd namethe" style="margin-left: 0.5rem;">
				          			<img src="../img/erweima.png">
				          			<input placeholder="请输入接种本上的儿童编码" id="jzCode" />
				          		</a>
							</li>
							<li class="am-g am-list-item-dated">
				          		<a href="##" class="am-list-item-hd namethe" onclick="return false" style="margin-left: 0.5rem;">
				          			<img src="../img/hospital.png">
				          			<input placeholder="选择接种点" id="place" readonly/>
				          		</a>
							</li>
							<!--<li class="am-g am-list-item-dated">
				          		<a href="##" class="am-list-item-hd namethe" onclick="return false" style="margin-left: 0.5rem;">
				          			<img src="../img/phone.png" style="width: 17px;">
				          			<input style="color: #b6bcce;" placeholder="手机号" value="18030775847  已通过验证" readonly="" id="phone" /> 
				          		</a>
				          	</li>-->
				      	</ul>
				  	</div>
				</div>
			</div>
		</div>
		<div class="footer">
			<button class="add" type="button">添加宝宝</button>
		</div>
		
		<!--内容没有填写完整-->
		<div class="am-modal am-modal-no-btn" tabindex="-1" id="collection">
			<div class="am-modal-dialog" style="border-radius: 5px;">
			    <div class="am-modal-bd">请完整信息!</div>
			</div>
		</div>
		<!--添加孩子失败-->
		<div class="am-modal am-modal-no-btn" tabindex="-1" id="colle">
			<div class="am-modal-dialog" style="border-radius: 5px;">
			    <div class="am-modal-bd failure">添加宝宝失败!</div>
			</div>
		</div>
		
		<div class="am-modal am-modal-loading am-modal-no-btn radius4" tabindex="-1" id="my-modal-loading" data-am-modal="{closeViaDimmer: 0}">
			  <div class="am-modal-dialog" style="border-radius: 4px;">
			    	<div class="am-modal-hd">加载中...</div>
				    <div class="am-modal-bd">
				      <span class="am-icon-spinner am-icon-spin"></span>
				    </div>
			  </div>
		</div>
		<script src="../assets/js/jquery.min.js"></script>
		<script src="../assets/js/jquery.cookie.js"></script>
		<script src="../assets/js/amazeui.min.js"></script>
		<script src="../assets/js/fastclick.min.js"></script>
		<script src="../assets/js/jquery.yomi.js"></script>
		<script src="../assets/choice/iosSelect.js"></script>
		<script src="../assets/js/datePicker.js"></script>
		<script src="../js/ym.js"></script>
		<script src="../assets/js/LAreaData2.js"></script>
    	<script src="../assets/js/LArea.js"></script>
		<script src="../js/public.js"></script>
		<script src="../js/data.js"></script>
		
		<script>
			$(function(){
				var mydata = new Date();
				var years = mydata.getFullYear();
				var months = mydata.getMonth()+1;
				var days = mydata.getDate();
				var place=[];
				var time = years +"-"+months+"-"+days;
				var theSelectData="";
				var charector="";
				var gender="1";
				var phone="";
				var addr="";
				var jzAddr="";
				/*获取当前用户的电话号码*/
				ym.ajax({
			            url: "/user/getUserPhone",
			            success: function (data) {
			               document.querySelector('#phone').value=data.obj+"  已通过验证";
			            }
			        });
				/*宝宝生日*/
				var calendar = new datePicker();
				calendar.init({
					'trigger': '#childuserBirthday', /*按钮选择器，用于触发弹出插件*/
					'type': 'date',/*模式：date日期；datetime日期时间；time时间；ym年月；*/
					'minDate':'1995-1-1',/*最小日期*/
					'maxDate':time,/*最大日期*/
					'onSubmit':function(){/*确认时触发事件*/
						theSelectData=calendar.value;
					},
					'onClose':function(){/*取消时触发事件*/
					}
				});
				
				
				/*性别点击事件*/
				var body = '<img src="../img/boy.png"><span>男</span>'
				var body1 = '<img src="../img/boy1.png"><span>男</span>'
				var girl = '<img src="../img/girl.png"><span>女</span>'
				var girl1 = '<img src="../img/girl1.png"><span>女</span>'
				$('.boy').on('click',function(){
					$(this).html(body1);
					$(this).css('color','#46c8ff');
					$(this).addClass("select");
					$(this).next().removeClass("select");
					$(this).next().html(girl);
					$(this).next().css('color','#999999');
					gender="1";
				})
				$('.girl').on('click',function(){
					$(this).html(girl1);
					$(this).css('color','#46c8ff');
					$(this).addClass("select");
					$(this).prev().removeClass("select");
					$(this).prev().html(body);
					$(this).prev().css('color','#999999');
					gender='2';
				})
				
				
				 //点击宝宝与我的关系
			    var showDombetween = document.querySelector('#between');
			    showDombetween.addEventListener('click', function () {
			    var bankSelect = new IosSelect(1, 
			            [between],
			            {
			                container: '.container',
			                title: '宝宝与我的关系',
			                callback: function (selectOneObj) {
			                    $("#between").val(selectOneObj.value);
			                    charector=selectOneObj.value;
			                },
			                fallback: function () {
			                    console.log(1);
			                },
			                maskCallback: function () {
			                    console.log(2);
			                }
			        });
			    });
			    
			    //接种所在地
			    var area2 = new LArea();
					var provs_data=[];
				    ym.ajax({
				    	url: "/areaController/queryTree",
				    	success: function (data) {
				    		if(data.obj){
				    			provs_data=data.obj;		
				    		}
				    		area2.init({
				    				'trigger': '#address',
				    				'valueTo': '#value2',
				    				'keys': {
				    						id: 'id',
				    						name: 'name'
				    				},
				    				'type': 1,
				    				'data':provs_data
				    		});
				    	}
				    })
				   var address=document.querySelector('#address');
				   address.addEventListener('blur', function () {
					   	var provinceCode=localStorage.getItem('provinceCode');
					   	var cityCode=localStorage.getItem('cityCode');
				    	var countyCode=localStorage.getItem('countyCode');
				    	addr=address.value;
				    	var data={};
				    	if(countyCode!=='null'){
				    		data={ countyAreaId:countyCode };
				    	}else if(countyCode==='null'&&cityCode!=='null'){
				    		data={ cityAreaId:cityCode };
				    	}else{
				    		data={ provinceAreaId:provinceCode };
				    	}
				    	/*查询地级市下面的接种点*/
				    	ym.ajax({
			            url: "/areaController/getStationDto",
			            param:data,
			            success: function (data) {
			            	if(data.obj){
			               		place=[];
			               		for (var i = 0; i < data.obj.length; i++) {
			               			place.push({id:data.obj[i].station_id,value:data.obj[i].station_name});
			               		}
			               }
			            }
			            });
				    });
			    //接种点
			    var showDomplace = document.querySelector('#place');
			    showDomplace.addEventListener('click', function () {
			    	console.log(place)
			    	
			    var bankSelect = new IosSelect(1, 
			            [place],
			            {
			                container: '.container',
			                title: '接种地点',
			                callback: function (selectOneObj) {
			                    $("#place").val(selectOneObj.value);
			                    jzAddr=selectOneObj.id;
			                },
			                fallback: function () {
			                    console.log(1);
			                },
			                maskCallback: function () {
			                    console.log(2);
			                }
			        });
			    });
			    /*添加宝宝*/
			    var addbtn=document.querySelector('.add');
			    addbtn.addEventListener('click', function () {
			    	var name = $('#childName').val();
			    	var code = $('#jzCode').val();
			    	var provinceCode = localStorage.getItem('provinceCode');
			    	var cityCode = localStorage.getItem('cityCode');
			    	var countyCode = localStorage.getItem('countyCode');
			    	if(theSelectData == "" || charector == "" || name == "" || code == "" || provinceCode == "" || cityCode == "" || jzAddr == ""){
			    		$("#collection").modal('open');
			    		setTimeout(function(){ $("#collection").modal('close');}, 500);
			    		return;
			    	}
			    	if(countyCode == "null"){
			    		countyCode = "";
			    	}
			    	var dataJson={
			    		 childBirthday:theSelectData,
			    		 relationship:charector,
			    		 childRealname:document.querySelector('#childName').value,
			    		 childSex:gender,
			    		 childCode:document.querySelector('#jzCode').value,
			    		 provinceAreaId:localStorage.getItem('provinceCode'),
			    		 cityAreaId:localStorage.getItem('cityCode'),
			    		 countyAreaId:countyCode,
			    		 vaccineStationId:jzAddr
			    	}
			    	ym.ajax({
			            url: "/userChild/insertUserChild",
			            param:dataJson,
			            success: function (data){
			            	var resets = $('.am-list-news-bd').find('input');
					    	$(resets).each(function(){
								$(this).val("");
							});
			               if(data.res == 1){
			               		window.location.href="myBaby.html";
			               }else{
			               		$('.failure').text(data.resMsg);
			               		$("#colle").modal('open');
			    				setTimeout(function(){ $("#colle").modal('close');}, 1000);
			               }
			            }
			        });
			    })
			})
		</script>
	</body>
</html>
